"""
字典的定义
"""
# 定义一个空字典
empty_dict = {}
empty_dict1 = dict()
print(empty_dict)  # 输出: {}
print(empty_dict1)
print(type(empty_dict))  # 输出: <class 'dict'>
print(type(empty_dict1))  # 输出: <class 'dict'>
# 定义重复键的字典，后面的值会覆盖前面的值
dup_dict = {"语文": 90,"语文": 88,  "数学": 95, "英语": 85}
print(dup_dict)  # 输出: {'语文': 88, '数学': 95, '英语': 85}
# 定义一个非空字典
person = {"name": "Alice", "age": 30, "city": "New York"}
print(person)  # 输出: {'name': 'Alice', 'age': 30, 'city': 'New York'}
print(type(person))  # 输出: <class 'dict'>
# 字典的键值对，从字典中基于键获取值
print("name:", person["name"])  # 输出: name: Alice
print("age:", person["age"])    # 输出: age: 30
print("city:", person["city"])  # 输出: city: New York
# 成绩单字典-嵌套字典
score_dict = {"王力鸿":{"语文": 90, "数学": 95, "英语": 85},
              "周杰伦":{"语文": 88, "数学": 92, "英语": 80},
              "林俊杰":{"语文": 85, "数学": 90, "英语": 88}}
print("王力鸿的语文成绩:", score_dict["王力鸿"]["语文"])  # 输出: 王力鸿的语文成绩: 90
print("周杰伦的数学成绩:", score_dict["周杰伦"]["数学"])  # 输出: 周杰伦的数学成绩: 92
print("林俊杰的英语成绩:", score_dict["林俊杰"]["英语"])  # 输出: 林俊杰的英语成绩: 88
# 字典不可以使用索引访问
# print(person[0])  # TypeError: 'dict' object is not subscriptable


